// 'use strict';
function checkToken(){
return async function(ctx,next){
    const {token}=ctx.request.header;
    console.log(token);
    if(token){
        
        try{

            const result =ctx.app.jwt.verify(token,ctx.app.config.jwt.sercet);


            if(result.end_time >= result.login_time){
                await next()

            }else{
                ctx.body={
                    code:4005,
                    msg:"token失效",
                };
            }
        }catch(err){
            ctx.body={
                code:4006,
                msg:"token验证失败",
            };
        }
    }else{
        ctx.body={
            code:4007,
            msg:"token不存在",
        };
    }
}
}
module.exports = checkToken;
